package com.itly.controller;

import com.itly.util.ApiResult;
import com.itly.entity.FillQuestion;
import com.itly.service.FillQuestionService;
import com.itly.util.ApiResultHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class FillQuestionController {
    private Logger logger = LoggerFactory.getLogger(FillQuestionController.class);

    @Autowired
    private FillQuestionService fillQuestionService;

    @PostMapping("fillQuestion")
    public ApiResult fillQuestion(@RequestBody FillQuestion fillQuestion) {
        int i = fillQuestionService.addFillQuestion(fillQuestion);
        if (i == 1) {
            logger.info("添加成功");
            return ApiResultHandler.buildApiResult(200, "添加成功", i);
        }
        logger.info("添加失败",fillQuestion);
        return ApiResultHandler.buildApiResult(400, "添加失败", i);
    }

    @GetMapping("fillQuestionId")
    public ApiResult fillQuestionId() {
        FillQuestion fillQuestion = fillQuestionService.fillQuestionId();
        logger.info("通过填空题ID查询填空题");
        return ApiResultHandler.buildApiResult(200, "查询填空题ID", fillQuestion);
    }
}
